﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SQLite;


namespace inspect
{
    class Program
    {
        void doInspectChip(InspectParam_Chip param)
        {
              
            
        }
        static void readParamDB(InspectParam_Chip clParam)
        { 
            string file = "H:/HD/partData.db";
            using (SQLiteConnection con = new SQLiteConnection("data source=" + file))
            {
                con.Open();
                string stm = "SELECT * FROM chip WHERE modelName = '0805R'";

                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            

                            clParam.No = Convert.ToInt32(rdr["DBNo"]);
                            clParam.modelName = rdr["modelName"].ToString();

                            clParam.inspectL = Convert.ToDouble(rdr["inspectL"]);
                            clParam.inspectW = Convert.ToDouble(rdr["inspectW"]);
                            clParam.inspectRou = Convert.ToDouble(rdr["inspectRo"]);
                            clParam.toleranceX = Convert.ToDouble(rdr["toleranceX"]);
                            clParam.toleranceY = Convert.ToDouble(rdr["toleranceY"]);
                            clParam.toleranceR = Convert.ToDouble(rdr["toleranceR"]);
                            clParam.padOffsetL = Convert.ToDouble(rdr["padOffsetL"]);
                            clParam.padEllipseR1 = Convert.ToDouble(rdr["padEllipseR1"]);
                            clParam.padEllipseR2 = Convert.ToDouble(rdr["padEllipseR2"]);

                            clParam.padHueMi = Convert.ToInt32(rdr["padHueMi"]);
                            clParam.padHueMi = Convert.ToInt32(rdr["padHueMa"]);
                            clParam.padDeviationMa = Convert.ToInt32(rdr["padDeviationMa"]);
                            clParam.padLRDeviationMa = Convert.ToInt32(rdr["padLRDeviationMa"]);

                            clParam.inspectBodyL = Convert.ToDouble(rdr["inspectBodyL"]);
                            clParam.inspectBodyW = Convert.ToDouble(rdr["inspectBodyW"]);

                            clParam.BodyMa = Convert.ToInt32(rdr["BodyMa"]);
                            clParam.BodyMi = Convert.ToInt32(rdr["BodyMi"]);
                            clParam.DeviationMa = Convert.ToInt32(rdr["DeviationMa"]);
                            clParam.DeviationMi = Convert.ToInt32(rdr["DeviationMi"]);


                            Console.WriteLine(System.Environment.TickCount);
                            Console.WriteLine(System.Environment.TickCount);
                        }
                    }
                }
                con.Close();
            }
        }
        static void Main(string[] args)
        {
            //InspectParam_Chip clParam = new InspectParam_Chip();
            //HDinspect clInspect = new HDinspect();
            //readParamDB(clParam);
            //传入图片，识别参数，角度，返回结果
            //clInspect.action();
            InspectCtr Inspect = new InspectCtr();
            Inspect.clDatas.LoadMntXML("H:/HD/1117N2YL.xml");
            Inspect.InspectComp();

            /*
             后处理
               0、分析出唯一焊盘，同类封装的器件
             * 1、分析位置角度偏差
             * 2、保证0满足，对同一订单，同类器件的数据计算出分布函数(正态分布or直方图找最高orSPC分析方法)，
             * 根据预置的标准差筛选NG，比如0.5%+5个，如果ng数量超过标准，继续向上筛选
             * 3、2无法实施时，对同一订单，相同位置的器件执行2的计算
             * 
             * xml存参数，和yamaha兼容？db存结果
             */
        }
    }
}
